import { Component } from '../../../components/base-component';
import { removingModal } from '../../../utilities/observable';

export class Announce extends Component {
  private announce = new Component({
    tag: 'h2',
    className: 'announce',
  });

  constructor(name?: string, time?: number, text = 'There is no winner') {
    super({ className: 'wrapper-announce' });

    const modal = new Component({ className: 'modal' });
    if (name && time) {
      this.announce.setTextContent(`The ${name} wins with time: ${time}s`);
    } else {
      this.announce.setTextContent(text);
    }

    modal.append(this.announce);

    removingModal.subscribe(() => {
      this.node.remove();
    });

    this.append(modal);
  }
}
